/**
 * 
 */
package ro.utcn.tp.taskManagement.gui;

import java.awt.Container;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.UIManager;

import ro.utcn.tp.taskManagement.business.ImageService;

/**
 * @author Coni
 * 
 */
public class ApplicationScreen {

	/** The main application frame. */
	private JFrame appFrame;

	/** The class instance. */
	private static ApplicationScreen instance;

	/**
	 * The private constructor if the ApplicationScreen class. Sets the
	 * application look and feel to the system look and feel and calls the
	 * createGUI method.
	 */
	private ApplicationScreen() {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			e.printStackTrace();
		}
		ImageService.getInstance();
		createGUI();
	}

	/**
	 * Initializes the application frame.
	 */
	private void createGUI() {
		appFrame = new JFrame("Task Management Application");
		appFrame.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				try {
					close();
				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
		});
		appFrame.setContentPane(LoginPage.getNewInstance().getContainer());

		appFrame.setLocation(200, 50);
		appFrame.setSize(800, 600);
		appFrame.setResizable(true);
		appFrame.setVisible(true);
	}

	public JFrame getFrame() {
		return appFrame;
	}

	/**
	 * Exits the application.
	 */
	public void close() {
		System.exit(0);
	}

	/**
	 * @return the instance of the class.
	 */
	public static ApplicationScreen getInstance() {
		if (instance == null) {
			instance = new ApplicationScreen();
		}
		return instance;
	}

	public void setContainer(Container container) {
		appFrame.setContentPane(container);
		appFrame.setVisible(true);

	}

}
